﻿// cookieControl version 5.1 (2012-06-19, RA, leigh)
// Copyright (c) 2012 Civic UK (http://www.civicuk.com/cookie-law/)
function cookieControl(a)
{
    if (typeof (a) == "undefined")
    {
        a = {
            pollPeriod: 25,
            pollIncrement: 1.25
        }
    }
    a.pollPeriod = a.pollPeriod || 25;
    a.pollIncrement = a.pollIncrement || 1.25;
    a.jQueryUrl = a.jQueryUrl || "http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js";
    if (typeof (jQuery) == "undefined" || parseInt(jQuery.fn.jquery.replace(/\./g, "")) < 144)
    { document.write('<script type="text/javascript" src="' + a.jQueryUrl + '"><\/script>') }
    _cookieControlPoll(a)
}
function _cookieControlPoll(a)
{
    if (typeof (jQuery) == "undefined")
    {
        setTimeout(function ()
        { _cookieControlPoll(a) }, a.pollPeriod); a.pollPeriod *= a.pollIncrement
    }
    else
    { jQuery(function () { CookieControl.init(a) }) }
}
var CookieControl =
    {
        options:
          {
              countries: "United Kingdom",
              shape: "triangle",
              position: "left",
              theme: "light",
              introText: "~introduction_text",
              fullText: "~full_text",
              cookieOnText: "Cookies are on",
              cookieOffText: "Cookies are off",
              cookieName: "civicAllowCookies",
              protectedCookies: [],
              iconStatusCookieName: "civicShowCookieIcon",
              cookiePath: "/",
              clickFadeSpeed: 1000,
              acceptDelay: 400,
              startOpen: false,
              autoHide: 60000,
              autoDelete: 60000,
              domain: "",
              subdomains: true,
              css: "",
              html: "",
              onReady: null,
              onCookiesAllowed: null,
              onCookiesNotAllowed: null,
              onAccept: null,
              consentModel: "information_only"
          },
        init: function (a)
        {
            this._jc = false;
            this.options = jQuery.extend(this.options, a);
            this.initWidget();
            this.readyEvent();
            if (this.maySendCookies())
            {
                this.cookiesAllowedEvent()
            }
            else
            {
                this.cookiesNotAllowedEvent()
            }
        },
        cookieLawApplies: function () {
            if (this.countryHasCookieLaw())
            { return true }
            return false
        },
        maySendCookies: function () {
            if (!this.cookieLawApplies()) { return true } if (this.consented()) { return true } return false
        }, consented: function () {
            return this._jc || (this.getCookie(this.options.cookieName) === "yes")
        },
        reset: function () {
            this.setCookie(this.options.cookieName, "", true);
            this.setCookie(this.options.iconStatusCookieName, "", true);
            this.setCookie("ccNoPopup", "", true)
        },
        initWidget: function () {
            if (!this.cookieLawApplies()) { return }
            if (this.getCookie(this.options.iconStatusCookieName) === "no") { return }
            this.initShowCookieWidget()
        },
        initShowCookieWidget: function () {
            var e = this.consented();
            if (jQuery("#cccwr .ccc-outer").length)
            { return }
            //jQuery("head").append('<style type="text/css">' + this.options.css + "</style>");
            jQuery("body").prepend(this.options.html);
            var a = jQuery("#ccc-icon");
            var c = jQuery("#ccc-state");
            jQuery("#cccwr").addClass("ccc-" + this.options.position);
            a.addClass("ccc-" + this.options.shape);
            jQuery("#cccwr .ccc-intro").append(this.options.introText);
            jQuery("#cccwr .ccc-expanded").prepend(this.options.fullText);
            jQuery("#cccwr").addClass("ccc-" + this.options.theme);
            a.show();
            c.addClass(e ? "ccc-go" : "ccc-pause");
            var d = this.getCookie(this.options.cookieName);
            switch (this.options.consentModel)
            {
                case "information_only":
                    c.removeClass("ccc-pause").addClass("ccc-go");
                    jQuery("#cctoggle-text").addClass("cctoggle-text-on");
                    jQuery("#cctoggle-text").html(CookieControl.options.cookieOnText);
                    break;
                case "implicit":
                    jQuery("#cccwr #ccc-cookies-switch").show();
                    if (!d) {
                        c.removeClass("ccc-pause").addClass("ccc-go");
                        jQuery("#cctoggle-text").addClass("cctoggle-text-on");
                        jQuery("#cctoggle-text").html(CookieControl.options.cookieOnText);
                        CookieControl._jc = true;
                        CookieControl.acceptEvent();
                        CookieControl.setCookie(CookieControl.options.cookieName, "yes");
                        CookieControl.cookiesAllowedEvent()
                    }
                    CookieControl.options.protectedCookies.push(CookieControl.options.cookieName);
                    break;
                case "explicit":
                    var b = this.getCookie("ccNoPopup");
                    if (b == "no")
                    {
                        jQuery("#cccwr #cchide-popup").attr("checked", true)
                    }
                    else
                    {
                        jQuery("#cccwr #cchide-popup").removeAttr("checked")
                    }
                    jQuery("#cccwr #ccc-cookies-switch").show();
                    Query("#cctoggle-text").addClass("cctoggle-text-off");
                    jQuery("#cctoggle-text").val(CookieControl.options.cookieOffText);
                    break;
            }
            if (this.options.consentModel != "information_only")
            {
                if (d == "yes") {
                    jQuery("#cccwr #ccc-cookies-switch #ccc-cookies-checkbox").attr("checked", true);
                    jQuery("#cctoggle").addClass("cctoggle-on");
                    jQuery("#cctoggle-text").removeClass("cctoggle-text-off").addClass("cctoggle-text-on");
                    jQuery("#cctoggle-text").html(CookieControl.options.cookieOnText);
                }
                else
                {
                    if (!d && this.options.consentModel == "implicit")
                    {
                        jQuery("#cccwr #ccc-cookies-switch #ccc-cookies-checkbox").attr("checked", true);
                        jQuery("#cctoggle").addClass("cctoggle-on");
                        jQuery("#cctoggle-text").removeClass("cctoggle-text-off").addClass("cctoggle-text-on");
                        jQuery("#cctoggle-text").html(CookieControl.options.cookieOnText)
                    }
                    else
                    {
                        jQuery("#cccwr #ccc-cookies-switch #ccc-cookies-checkbox").removeAttr("checked");
                        jQuery("#cctoggle").removeClass("cctoggle-on");
                        jQuery("#cctoggle-text").removeClass("cctoggle-text-on").addClass("cctoggle-text-off");
                        jQuery("#cctoggle-text").html(CookieControl.options.cookieOffText);
                        if (CookieControl.options.consentModel == "implicit")
                        {
                            jQuery("#cccwr #ccc-implicit-warning").show();
                        }
                        else
                        {
                            if (CookieControl.options.consentModel == "explicit")
                            {
                                jQuery("#cccwr #ccc-explicit-checkbox").show()
                            }
                        }
                    }
                }
            }
            else
            {
                if (d == false)
                {
                    c.removeClass("ccc-pause").addClass("ccc-go");
                    jQuery("#cctoggle-text").removeClass("cctoggle-text-off").addClass("cctoggle-text-on");
                    jQuery("#cctoggle-text").html(CookieControl.options.cookieOnText);
                    CookieControl._jc = true;
                    CookieControl.acceptEvent();
                    CookieControl.setCookie(CookieControl.options.cookieName, "yes");
                    CookieControl.cookiesAllowedEvent()
                }
            }
            a.click(function (f) {
                f.preventDefault();
                jQuery("#cccwr .ccc-widget").clearQueue().fadeToggle(CookieControl.options.clickFadeSpeed);
            });
            jQuery("#cccwr #cchide-popup").click(function (g) {
                var f = jQuery(this).attr("checked");
                var h = CookieControl;
                if (f == true) {
                    h.setCookie("ccNoPopup", "no");
                    jQuery("#cccwr .ccc-widget").fadeOut(CookieControl.options.clickFadeSpeed);
                }
                else
                {
                    h.setCookie("ccNoPopup", "", true);
                }
            });
            jQuery("#cccwr .ccc-close").click(function (f) {
                f.preventDefault();
                jQuery("#cccwr .ccc-widget").clearQueue().fadeOut(CookieControl.options.clickFadeSpeed);
            });
            jQuery("#cccwr .ccc-expand").click(function () {
                var f = jQuery(this);
                if (jQuery(".ccc-expanded").css("display") === "none") {
                    jQuery(".ccc-expanded").slideDown(200, function () { f.text("read less") }); jQuery(this).css({ backgroundPosition: "center 0" })
                }
                else
                {
                    jQuery(".ccc-expanded").slideUp(200, function () {
                        f.text("read more");
                    });
                    jQuery(this).css({ backgroundPosition: "center -9px" });
                }
            });
            jQuery("#cctoggle").click(function () {
                if (jQuery(this).hasClass("cctoggle-on")) {
                    jQuery("#cctoggle-text").html("");
                    jQuery("#cctoggle-text").removeClass("cctoggle-text-on");
                    jQuery(this).animate({ "background-position-x": "0" }, 250, function () {
                        jQuery(this).removeClass("cctoggle-on");
                        c.removeClass("ccc-go").addClass("ccc-pause"); CookieControl._jc = false;
                        if (CookieControl.options.consentModel != "explicit") {
                            CookieControl.setCookie(CookieControl.options.cookieName, "no");
                        }
                        else {
                            CookieControl.setCookie(CookieControl.options.cookieName, "", true);
                        }
                        CookieControl.cookiesNotAllowedEvent();
                        if (CookieControl.options.consentModel == "implicit") {
                            jQuery("#cccwr #ccc-implicit-warning").slideDown();
                            jQuery("#cccwr .ccc-widget").fadeOut(5000);
                        }
                        else {
                            if (CookieControl.options.consentModel == "explicit") {
                                if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) === 7) {
                                    jQuery("#cccwr #ccc-explicit-checkbox").show();
                                }
                                else {
                                    jQuery("#cccwr #ccc-explicit-checkbox").slideDown();
                                }
                            }
                        }
                        jQuery("#cctoggle-text").addClass("cctoggle-text-off");
                        jQuery("#cctoggle-text").html(CookieControl.options.cookieOffText);
                        CookieControl.delAllCookies(CookieControl.options.protectedCookies);
                    });
                }
                else
                {
                    jQuery("#cctoggle-text").html("");
                    jQuery("#cctoggle-text").removeClass("cctoggle-text-off");
                    jQuery(this).animate({ "background-position-x": "100%" }, 250, function () {
                        jQuery(this).addClass("cctoggle-on");
                        c.removeClass("ccc-pause").addClass("ccc-go");
                        CookieControl._jc = true;
                        CookieControl.acceptEvent();
                        CookieControl.setCookie(CookieControl.options.cookieName, "yes");
                        CookieControl.cookiesAllowedEvent();
                        if (CookieControl.options.consentModel == "implicit")
                        {
                            jQuery("#cccwr #ccc-implicit-warning").slideUp();
                        }
                        else
                        {
                            if (CookieControl.options.consentModel == "explicit")
                            {
                                jQuery("#cccwr #ccc-explicit-checkbox").slideUp();
                            }
                        }
                        jQuery("#cctoggle-text").addClass("cctoggle-text-on");
                        jQuery("#cctoggle-text").html(CookieControl.options.cookieOnText);
                        jQuery("#cccwr .ccc-widget").fadeOut(2000);
                    })
                }
            });
            var b = this.getCookie("ccNoPopup");
            if (this.options.startOpen && d != "yes" && d != "no" && b != "no")
            {
                jQuery("#cccwr .ccc-widget").fadeIn(this.options.clickFadeSpeed).delay(this.options.autoHide).fadeOut(this.options.clickFadeSpeed, function () {
                    if (!CookieControl.getCookie(CookieControl.options.cookieName) && CookieControl.options.consentModel != "explicit")
                    {
                        CookieControl._jc = false;
                        CookieControl.setCookie(CookieControl.options.cookieName, "no");
                        CookieControl.cookiesNotAllowedEvent();
                    }
                });
                jQuery("#cccwr .ccc-widget").mouseover(function () {
                    jQuery("#cccwr .ccc-widget").clearQueue();
                    if (!CookieControl.getCookie(CookieControl.options.cookieName) && CookieControl.options.consentModel != "explicit")
                    {
                        CookieControl._jc = false;
                        CookieControl.setCookie(CookieControl.options.cookieName, "no");
                        CookieControl.cookiesNotAllowedEvent();
                    }
                })
            }
        },
        countryHasCookieLaw: function () {
            if (this.options.countries && typeof (geoplugin_countryName) === "function")
            {
                var a = geoplugin_countryName().replace(/^\s+|\s+$/g, "");
                if (typeof (this.options.countries) === "string")
                {
                    this.options.countries = this.options.countries.split(/\s*,\s*/);
                }
                return jQuery.inArray(geoplugin_countryName().replace(/^\s+|\s+$/g, ""), this.options.countries) >= 0;
            }
            return true
        },
        checkShowIconState: function () {
            var a = CookieControl;
            if (jQuery(".ccc-widget input[name=showicon]:checked").val() === "N")
            {
                this.setCookie(a.options.iconStatusCookieName, "no");
                return true;
            }
            else
            {
                this.setCookie(a.options.iconStatusCookieName, "yes");
                return false;
            }
        },
        setCookie: function (a, k, b, l) {
            var e = "Thursday, 01-Jan-1970 00:00:01 GMT";
            if (!b)
            {
                var g = new Date();
                var d = 1000 * 60 * 60 * 24 * 90;
                var c = new Date(g.getTime() + d);
                var e = c.toGMTString();
            }
            var f = this.options.domain;
            if (f.length === 0)
            {
                var i = window.location.hostname;
                var h = 2;
                if (i.match(/\.(gov|police|org|co|uk|ltd|me|plc|ac|net)\.\w{2}/))
                {
                    h = 3;
                }
                var j = i.split(".").reverse();
                j.length = h;
                f = j.reverse().toString().replace(/,/g, ".");
            }
            if (this.options.subdomains === true)
            { domainString = ";domain=" + f }
            else
            {
                domainString = ";domain=" + i;
            }
            document.cookie = a + "=" + k + ";expires=" + e + ";path=" + this.options.cookiePath + domainString;
        },
        getCookie: function (a) {
            var b = false;
            jQuery.each(document.cookie.split(";"), function (e, f) {
                    var d = f.split("=");
                    if (d[0].replace(/^\s+|\s+$/g, "") === a) {
                        b = unescape(d[1]);
                        return false;
                    }
            });
            if ("undefined" === typeof b)
            {
                b = false;
            }
            return b;
        },
        delCookie: function (a, c, d) {
            var c = c || document.domain;
            var d = d || "/";
            var b = a + "=;expires=Thursday, 01-Jan-1970 00:00:01 GMT;; domain=" + c + "; path=" + d;
            document.cookie = b;
        },
        delAllCookies: function (d) {
            if (!this.options.autoDelete) { return } var e = document.cookie.split(/;\s*/); var c; for (c = 0; c < e.length; c++) { var b = e[c]; var f = b.indexOf("="); var a = f > -1 ? b.substr(0, f) : b; if (jQuery.inArray(a, d) < 0) { this.setCookie(a, "", true); this.delCookie(a) } }
        },
        acceptEvent: function (a) {
            if (this.firedAcceptEvent || this.getCookie(this.options.cookieName) === "yes")
            {
                return;
            }
            this.firedAcceptEvent = true;
            if (typeof (this.options.onAccept) == "function")
            {
                this.options.onAccept(this);
            }
            return a;
        },
        readyEvent: function (a) {
            if (typeof (this.options.onReady) == "function")
            {
                this.options.onReady(this);
            }
            return a;
        },
        cookiesNotAllowedEvent: function (a) {
            if (typeof (this.options.onCookiesNotAllowed) == "function") {
                this.options.onCookiesNotAllowed(this);
            }
            return a;
        },
        cookiesAllowedEvent: function (a) {
            if (typeof (this.options.onCookiesAllowed) == "function")
            {
                this.options.onCookiesAllowed(this);
            }
            return a;
        }
    };